package com.tensquare.qa.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface ProblemRepository extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

    /**
    * @Description: 根据标签id查询最新回复的问题列表
    * @Param: [id, pageable]
    * @return: org.springframework.data.domain.Page<com.tensquare.qa.pojo.Problem>
    * @Author: NieMiao
    * @Date: 2018/12/24
    */
    @Query(value = "select * from Problem where id in (select problemid from Pl where lableid = ?1) order by replytime desc",nativeQuery = true)
    public Page<Problem> findNewListByLabelId(String id, Pageable pageable);
    
    /** 
    * @Description: 根据标签id查询最多回复问题列表
    * @Param: [id, pageable] 
    * @return: org.springframework.data.domain.Page<com.tensquare.qa.pojo.Problem> 
    * @Author: NieMiao 
    * @Date: 2018/12/24 
    */ 
    @Query(value = "select * from Problem where id in (select problemid from Pl where lableid = ?1) order by reply desc",nativeQuery = true)
    public Page<Problem> findHotListByLabelId(String id,Pageable pageable);
    
    /** 
    * @Description:  根据标签ID查询等待回答列表
    * @Param: [id, pageable] 
    * @return: org.springframework.data.domain.Page<com.tensquare.qa.pojo.Problem> 
    * @Author: NieMiao 
    * @Date: 2018/12/24 
    */ 
    @Query(value = "select * from Problem where id in (select problemid from Pl where lableid = ?1) order by createtime desc",nativeQuery = true)
    public Page<Problem> findWaitListByLabelId(String id,Pageable pageable);
}
